home *** CD-ROM | disk | FTP | other *** search
/ Aminet 50 / Aminet 50 (2002)(GTI - Schatztruhe)[!][Aug 2002].iso / Aminet / text / edit / tecoc-146.lha / exerbr.c < prev    next >
C/C++ Source or Header  |  1991-07-05  |  2KB  |  84 lines

  1. /*****************************************************************************
  2.  
  3.     ExeRBr()
  4.  
  5.     This function executes a ] command.
  6.     ]q    Q-register pop
  7.  
  8. *****************************************************************************/
  9.  
  10. #include "zport.h"        /* define portability identifiers */
  11. #include "tecoc.h"        /* define general identifiers */
  12. #include "defext.h"        /* define external global variables */
  13. #include "deferr.h"        /* define identifiers for error messages */
  14.  
  15. DEFAULT ExeRBr()                /* execute ] command */
  16. {
  17.     QRptr        TmpQRp;
  18.     ptrdiff_t    TmpSiz;
  19.     BOOLEAN        ColonMod;
  20.  
  21. #if DEBUGGING
  22.     static char *DbgFNm = "ExeRBr";
  23.     sprintf(DbgSBf, "QStTop = %d", QStTop);
  24.     DbgFEn(1,DbgFNm,DbgSBf);
  25. #endif
  26.  
  27.     ColonMod = (CmdMod & COLON);        /* is it :] ? */
  28.     CmdMod &= ~COLON;            /* clear colon flag */
  29.  
  30.     if (IncCBP() == FAILURE) {
  31.         return FAILURE;
  32.     }
  33.  
  34.     if (FindQR() == FAILURE) {
  35.         DBGFEX(1,DbgFNm,"FAILURE");
  36.         return FAILURE;
  37.     }
  38.  
  39.     if (QStTop < 0)    {            /* if q-reg stack is empty */
  40.         if (ColonMod) {            /* if it's :] */
  41.             DBGFEX(1,DbgFNm,"PushEx(0)");
  42.             return PushEx(0L, OPERAND);
  43.         } else {
  44.             ErrMsg(ERR_PES);    /* can't pop empty stack */
  45.             DBGFEX(1,DbgFNm,"FAILURE");
  46.             return FAILURE;
  47.         }
  48.     }
  49.  
  50. /*
  51.  * Copy QStack Q-register to QR
  52.  */
  53.     TmpQRp = &QStack[QStTop];
  54.     TmpSiz = TmpQRp->End_P1 - TmpQRp->Start;
  55.     if (TmpSiz == 0) {            /* if it should be empty */
  56.         if (QR->Start != NULL) {        /* but it isn't empty */
  57.             ZFree((voidptr)QR->Start);    /* then empty it */
  58.             QR->Start = QR->End_P1 = NULL;
  59.         }
  60.     } else {
  61.         if (MakRom((SIZE_T)TmpSiz) == FAILURE) { /* adjust QR space */
  62.             DBGFEX(1,DbgFNm,"FAILURE");
  63.             return FAILURE;
  64.         }
  65.         MEMMOVE(QR->Start, TmpQRp->Start, (SIZE_T)TmpSiz);
  66.         QR->End_P1 = QR->Start + TmpSiz;
  67.     }
  68.     QR->Number = TmpQRp->Number;
  69.  
  70. /*
  71.  * clear QStack Q-register
  72.  */
  73.     if (TmpQRp->Start != NULL) {
  74.         ZFree((voidptr)TmpQRp->Start);
  75.         TmpQRp->Start = TmpQRp->End_P1 = NULL;
  76.     }
  77.     TmpQRp->Number = 0;
  78.  
  79.     --QStTop;
  80.  
  81.     DBGFEX(1,DbgFNm,(ColonMod) ? "PushEx(-1)" : "SUCCESS");
  82.     return (ColonMod) ? PushEx(-1L, OPERAND) : SUCCESS;
  83. }
  84.